#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gtk/gtk.h>
#include <stdio.h>   
#include <string.h>  
#include <ctype.h>
#include <stdlib.h>
#include "callbacks.h"
#include "interface.h"
#include "support.h"
#include "menu.h"
#include "gestion_capteurs.h"
#include "Personnel.h" //pour le volet métier de l'application
#include "modifier_per.h"



void on_button1_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget * window2;
	window2 = create_window2();
	gtk_widget_show (window2);
}



void on_button2_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget * window3;	
	window3 = create_window3();
	gtk_widget_show (window3);
	GtkWidget * label14;
	char fichier[] = "personnels.txt";
	window3 = create_window3 ();
	gtk_widget_show (window3);
	label14= lookup_widget(objet_graphique, "label14");

	lister_personnel(fichier);

	sprintf(Buf0, "%s %d \n\n %s %s \n\n %s %s \n\n %s %ld \n\n %s %d \n\n %s %s \n\n %s %ld \n\n %s %s \n\n %s %s \n\n %s %d %d %d \n\n", Buf0, p.ID, Buf1,p.nom, Buf2, p.prenom, Buf3, p.cin, Buf4, p.age, Buf5, p.sexe, Buf6, p.numero_telephone, Buf7,p.adresse, Buf8, p.poste, Buf9, p.date_d_embauche.jour, p.date_d_embauche.mois, p.date_d_embauche.annee );

gtk_label_set_text(GTK_LABEL(label14), Buf0);
}



void on_button3_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget * window4;
	window4 = create_window4();
	gtk_widget_show (window4);
}



void on_button4_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget * window5;
	window5 = create_window5();
	gtk_widget_show (window5);
}



void on_button5_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget * window6;
	window6 = create_window6();
	gtk_widget_show (window6);
}



void on_button6_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget * window7;
window7 = create_window7();
gtk_widget_show (window7);
char fichier[] = "personnels.txt";
GtkWidget * label36;
init_personnels(fichier);
label36= lookup_widget(objet_graphique, "label36");
}



void on_button7_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window8;
	window8 = create_window8();
	gtk_widget_show (window8);
	GtkWidget * label38;
	char fichier[] = "tmp2.txt";
	label38= lookup_widget(objet_graphique, "label38");

	lister_personnel(fichier);

	sprintf(Buf0, "%s %d \n\n %s %s \n\n %s %s \n\n %s %ld \n\n %s %d \n\n %s %s \n\n %s %ld \n\n %s %s \n\n %s %s \n\n %s %d %d %d \n\n", Buf0, p.ID, Buf1,p.nom, Buf2, p.prenom, Buf3, p.cin, Buf4, p.age, Buf5, p.sexe, Buf6, p.numero_telephone, Buf7,p.adresse, Buf8, p.poste, Buf9, p.date_d_embauche.jour, p.date_d_embauche.mois, p.date_d_embauche.annee );

gtk_label_set_text(GTK_LABEL(label38), Buf0);
}



void on_button8_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window0;
	window0 = create_window0();
	gtk_widget_show (window0);
}



void on_button9_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	personnel p;
	char fichier[] = "personnels.txt";
	char tmp2[] = "tmp2.txt";

	GtkWidget *entry1;
	GtkWidget *entry2;
	GtkWidget *entry3;
	GtkWidget *entry4;
	GtkWidget *entry5;
	GtkWidget *entry6;
	GtkWidget *entry7;
	GtkWidget *entry8;
	GtkWidget *entry9;	
	GtkWidget *entry10;
	GtkWidget *entry11;
	GtkWidget *entry12;

	entry1 = lookup_widget(objet_graphique, "entry1");
	entry2 = lookup_widget(objet_graphique, "entry2");
	entry3 = lookup_widget(objet_graphique, "entry3");
	entry4 = lookup_widget(objet_graphique, "entry4");
	entry5 = lookup_widget(objet_graphique, "entry5");
	entry6 = lookup_widget(objet_graphique, "entry6");
	entry7 = lookup_widget(objet_graphique, "entry7");
	entry8 = lookup_widget(objet_graphique, "entry8");
	entry9 = lookup_widget(objet_graphique, "entry9");
	entry10 = lookup_widget(objet_graphique, "entry10");
	entry11= lookup_widget(objet_graphique, "entry11");
	entry12= lookup_widget(objet_graphique, "entry12");


	p.ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry1)));
	strcpy(P.nom, gtk_entry_get_text(GTK_ENTRY(entry2)));
	strcpy(P.prenom, gtk_entry_get_text(GTK_ENTRY(entry3)));
	p.cin = atoi(gtk_entry_get_text(GTK_ENTRY(entry4)));
	P.age = atoi(gtk_entry_get_text(GTK_ENTRY(entry5)));
	strcpy(p.sexe, gtk_entry_get_text(GTK_ENTRY(entry6)));
	p.numero_telephone = atoi(gtk_entry_get_text(GTK_ENTRY	(entry7)));
	strcpy(p.adresse, gtk_entry_get_text(GTK_ENTRY(entry8)));
	strcpy(p.poste, gtk_entry_get_text(GTK_ENTRY(entry9)));
	p.date_d_embauche.jour = atoi(gtk_entry_get_text(GTK_ENTRY	(entry10)));
	p.date_d_embauche.mois = atoi(gtk_entry_get_text(GTK_ENTRY	(entry11)));
	p.date_d_embauche.annee = atoi(gtk_entry_get_text(GTK_ENTRY	(entry12)));

	enregistrer_personnel(fichier,p,tmp2);
}



void on_button10_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	gtk_widget_show (window1);
}



void on_button11_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	gtk_widget_show (window1);
}



void on_button12_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	personnel p;
	char fichier[] = "personnels.txt";
	int ID;
	char nom[];
	int res=0;
	GtkWidget *entry8;
	GtkWidget *entry9;
	GtkWidget * label18;
	GtkWidget * label19;
	entry8 = lookup_widget(objet_graphique, "entry8");
	entry9 = lookup_widget(objet_graphique, "entry9");
	label18= lookup_widget(objet_graphique, "label18");
	label19= lookup_widget(objet_graphique, "label19");
	strcpy(P.nom, gtk_entry_get_text(GTK_ENTRY(entry8)));	
	p.ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry9)));
	
	res=chercher_personnel(fichier,nom,ID);
	if (res==1)
	{sprintf(Buf1,"Le personnel %s existe \n",nom);
	gtk_label_set_text(GTK_LABEL(label18), Buf1);

	sprintf(Buf0, "%s %d \n\n %s %s \n\n %s %s \n\n %s %ld \n\n %s %d \n\n %s %s \n\n %s %ld \n\n %s %s \n\n %s %s \n\n %s %d %d %d \n\n", Buf0, p.ID, Buf1,p.nom, Buf2, p.prenom, Buf3,p.cin, Buf4, p.age, Buf5, p.sexe, Buf6, p.numero_telephone, Buf7,p.adresse, Buf8, p.poste, Buf9, p.date_d_embauche.jour, p.date_d_embauche.mois, p.date_d_embauche.annee );
gtk_label_set_text(GTK_LABEL(label19), Buf0);
	}
	else {sprintf(Buf1,"Le personnel %s n'existe pas \n",nom);
		gtk_label_set_text(GTK_LABEL(label18), Buf1);}
}



void on_button13_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	gtk_widget_show (window1);
}



void on_button14_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	personnel p;
	char fichier[] = "personnels.txt";
	char tmp[] = "tmp.txt";
	char tmp[] = "tmp2.txt";
	int ID;
	GtkWidget *entry10;
	GtkWidget * label22;
	entry10 = lookup_widget(objet_graphique, "entry10");
	label22= lookup_widget(objet_graphique, "label22");
	supprimer_personnel(fichier);
	sprintf(Buf0,"Le personnel a été supprimé");
		gtk_label_set_text(GTK_LABEL(label22), Buf0);
}



void on_button15_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	gtk_widget_show (window1);
}



void on_button16_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
//la fonction modifier à revoir aprés
}



void on_button17_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	gtk_widget_show (window1);
}



void on_button18_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	gtk_widget_show (window1);
}



void on_button19_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	gtk_widget_show (window1);
}







void
on_button20_clicked  (GtkWidget *objet_graphique, gpointer         user_data)
{
capteur c;
char ges[]="Liste_capteurs.txt" ;
GtkWidget *entry1 ;
GtkWidget *entry2 ;
entry1 = lookup_widget(objet_graphique, "entry1");
entry2 = lookup_widget(objet_graphique, "entry2");
strcpy(c.cap,gtk_entry_get_text(GTK_ENTRY(entry1)));
strcpy(c.designation,gtk_entry_get_text(GTK_ENTRY(entry2))) ;
ajouter_capteur(ges,c) ;
}


void
on_button21_clicked   (GtkWidget *objet_graphique, gpointer    user_data)  
{
afficher_menu();
}


void
on_button22_clicked    (GtkWidget *objet_graphique, gpointer    user_data)                
capteur c ;
char nom[50] ;
char ges[]="Liste_capteurs.txt" ;
GtkWidget *entry1 ;
entry1 = lookup_widget(objet_graphique, "entry1");
strcpy(nom,gtk_entry_get_text(GTK_ENTRY(entry1)));
supprimer_capteur(ges);
}



void
on_button23_clicked   (GtkWidget   *objet_graphique, gpointer         user_data)          
{
afficher_menu();
}





void on_button24_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{
GtkWidget * window9;
	gtk_widget_show (window9);
}
                                        
void on_button25_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{
capteur c ;
char ges[]="Liste_capteurs.txt" ;
afficher_capteur(ges,c) ;
}
                    
void on_button26_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{

GtkWidget * window10;
	gtk_widget_show (window10);
} 

void on_button27_clicked(GtkWidget *objet_graphique,gpointer  user_data)

{
char ges[]="Liste_capteurs.txt" ;
init_capteur(ges) ;
}
                    
void on_button29_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{


}



void on_button31_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{
afficher_menu();
}


void on_button32_clicked(GtkWidget *objet_graphique,gpointer 
user_data)                   
{
GtkWidget * window12;
	gtk_widget_show (window12);
}


void
on_button33_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{

}

